package com.bookmanage.dao;

import java.sql.*;
import java.util.ArrayList;

import com.bookmanage.book.BookLose;
import com.bookmanage.utils.DBUitls;

public class BookLoseConn {
    //用于存BookLose
    static ArrayList<BookLose> list = new ArrayList<BookLose>();

    public static ArrayList<BookLose> list_return() {

        try {
            Connection conn = DBUitls.getConn();

            String sql = "select * from bookloserent ";
            //预处理编译sql
            PreparedStatement pst = (PreparedStatement) conn.prepareStatement(sql);
            ResultSet rs = (ResultSet) pst.executeQuery();
            if (conn != null) {
                // System.out.print("success!");
                while (rs.next()) {
                    //从数据库获取书籍信息
                    int number = rs.getInt("number");
                    String booklose = rs.getString("booklose");
                    //存入到Book类里面
                    BookLose book = new BookLose();
                    book.setNumber(number);
                    book.setBooklose(booklose);
                    list.add(book);
                }

            } else {
                System.out.println("数据库连接失败");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //将list返回，方便jsp界面调用
        return list;
    }

}
